package com.qiaofang.collectmanage.facade.impl;


import com.qiaofang.collectmanage.service.HouseAgentService;
import com.qiaofang.collectmanage.stub.bean.BatchGetHouseAgentRepeatDTO;
import com.qiaofang.collectmanage.stub.bean.HouseAgentDTO;
import com.qiaofang.collectmanage.stub.bean.SearchHouseAgentPageDTO;
import com.qiaofang.collectmanage.stub.facade.HouseAgentFacade;
import com.qiaofang.collectmanage.stub.request.*;
import com.qiaofang.collectmanage.stub.response.*;
import com.qiaofang.common.constant.CommonResponseCode;
import com.qiaofang.common.response.CommonResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

@RestController
public class HouseAgentFacadeImpl implements HouseAgentFacade {

    private final HouseAgentService houseAgentService;

    @Autowired
    public HouseAgentFacadeImpl(HouseAgentService houseAgentService) {
        this.houseAgentService = houseAgentService;
    }


    @Override
    public CommonResponse saveHouseAgent(@RequestBody @Valid SaveHouseAgentRequest request) {
        houseAgentService.saveHouseAgent(request.getSaveHouseAgentDTO());
        return new CommonResponse();
    }

    @Override
    public CommonResponse removeHouseAgent(@RequestBody @Valid RemoveHouseAgentRequest request) {
        houseAgentService.removeHouseAgent(request.getRemoveHouseAgentDTO());
        return new CommonResponse();
    }

    @Override
    public CommonResponse updateHouseAgent(@RequestBody @Valid UpdateHouseAgentRequest request) {
        houseAgentService.updateHouseAgent(request.getUpdateHouseAgentDTO());
        return new CommonResponse();
    }

    @Override
    public CommonResponse batchUpdateHouseAgent(@RequestBody @Valid BatchUpdateHouseAgentRequest request) {
        houseAgentService.batchUpdateHouseAgent(request.getBatchUpdateHouseAgentDTOs());
        return new CommonResponse();
    }

    @Override
    public BatchGetHouseAgentRepeatResponse batchGetHouseAgentRepeat(@RequestBody @Valid BatchUpdateHouseAgentRequest request) {
        BatchGetHouseAgentRepeatResponse batchGetHouseAgentRepeatResponse = new BatchGetHouseAgentRepeatResponse();
        List<BatchGetHouseAgentRepeatDTO> batchGetHouseAgentRepeatDTOS = houseAgentService.batchGetHouseAgentRepeat(request.getBatchUpdateHouseAgentDTOs());
        batchGetHouseAgentRepeatResponse.setData(batchGetHouseAgentRepeatDTOS);
        return batchGetHouseAgentRepeatResponse;
    }

    @Override
    public CommonResponse batchSaveHouseAgent(@RequestBody @Valid BatchUpdateHouseAgentRequest request) {
        houseAgentService.batchSaveHouseAgent(request.getBatchUpdateHouseAgentDTOs());
        return new CommonResponse();
    }

    @Override
    public SearchHouseAgentPageResponse searchHouseAgentPage(@RequestBody @Valid SearchHouseAgentPageRequest request) {
        SearchHouseAgentPageResponse response = new SearchHouseAgentPageResponse();
        List<HouseAgentDTO> list = houseAgentService.searchHouseAgentPage(request.getSearchHouseAgentPostDTO(), request.getPageDTO());
        SearchHouseAgentPageDTO searchHouseAgentPageDTO = new SearchHouseAgentPageDTO();
        searchHouseAgentPageDTO.setData(list);
        searchHouseAgentPageDTO.setCount(houseAgentService.countSearchHouseAgentPage(request.getSearchHouseAgentPostDTO(), request.getPageDTO()));
        response.setData(searchHouseAgentPageDTO);
        response.setResponseCode(CommonResponseCode.RC_SUCCESS.getResponseCode());
        response.setResponseMessage(CommonResponseCode.RC_SUCCESS.getResponseMessage());
        return response;
    }

    @Override
    public GetHouseAgentResponse getHouseAgent(@RequestBody @Valid GetHouseAgentRequest request) {
        GetHouseAgentResponse response = new GetHouseAgentResponse();
        HouseAgentDTO houseAgentDTO = houseAgentService.getHouseAgent(request.getGetHouseAgentDTO());
        response.setData(houseAgentDTO);
        return response;
    }

}
